


clear all 
use the_dataset.dta

keep if  standard == 1

global covariates1 culture1 educ_basic1-educ_sup1 age051-age661 income1 NMIEMB1 size_dummy1-size_dummy5 number_spanish1
global covariates2 culture1 educ_basic1-educ_sup1 age051-age661 income1 NMIEMB1 size_dummy1-size_dummy5 number_spanish1 ccaadummy1-ccaadummy17 
global covariates3 culture1 educ_basic1-educ_sup1 age051-age661 income1 NMIEMB1 size_dummy1-size_dummy5 number_spanish1 ccaadummy1-ccaadummy17 yeardummy1-yeardummy9


* 1. Normalized differences, Raw and After matching T01
preserve
keep if case_1==1
teffects nnmatch (culture_d $covariates1) (unemp), ematch(CCAA1 ANOENC1) nneighbor(3) atet biasadj($covariates1)
tebalance summarize
restore

*1.2 Normalized differences, Raw and After matching T12
preserve
keep if case_2==1
teffects nnmatch (culture_d $covariates2) (unemp) if case_2==1 , ematch(ANOENC1) nneighbor(3) atet biasadj($covariates2)
tebalance summarize
restore


* 1.3 Normalized differences, weighted
preserve
keep if case_1 == 1

logit unemp $covariates3
predict ps
sum unemp
scalar p=r(mean)
*Weights for treated equal to 1, for untreated estimated weights
gen     weights =1       if unemp == 1
replace weights = (ps/(1-ps)) if unemp == 0
summarize weights
scalar N=r(N)
scalar tot = r(mean) 
* create the correct weights dividing the estimated weights by the average weight 
gen weights2 = (weights)/tot
sum weights2

foreach x of varlist culture1 income1 NMIEMB1 educ_basic1-educ_sup1 ///
age051-age661 ccaadummy1-ccaadummy17 yeardummy1-yeardummy9 size_dummy1-size_dummy5  number_spanish1 {

sum `x' [iweight=weights2] if unemp==1
scalar m1`x'=r(mean)
scalar s1`x'=r(sd)
sum `x' [iweight=weights2] if unemp==0
scalar m0`x'=r(mean)
scalar s0`x'=r(sd)
scalar smd`x'=(m1`x'-m0`x')/(sqrt(((s1`x'^2)+(s0`x'^2))/2))
gen smd`x' = smd`x'
sum smd`x'

}
*
* pick covariate of interest
* income1 NMIEMB1 educ_basic1-educ_sup1 age051-age661 ccaadummy1-ccaadummy17 yeardummy1-yeardummy9 size_dummy1-size_dummy5  number_spanish
local covs1 income1
gen   covs1 = `covs1'

sum covs1 [iweight=weights2] if unemp==1
scalar m1=r(mean)
scalar s1=r(sd)
sum covs1 [iweight=weights2] if unemp==0
scalar m0=r(mean)
scalar s0=r(sd)
scalar smd=(m1-m0)/(sqrt(((s1^2)+(s0^2))/2))
scalar vr=(s1^2)/(s0^2)
dis "standardized mean difference = " smd 
dis "variance ratio = " vr
 restore


*1.4 Normalized differences, weighted
preserve 
keep if case_2 == 1

logit unemp $covariates3
predict ps
sum unemp
scalar p=r(mean)
*Weights for treated equal to 1, for untreated estimated weights
gen     weights =1       if unemp == 1
replace weights = (ps/(1-ps)) if unemp == 0
summarize weights
scalar N=r(N)
scalar tot = r(mean) 
* create the correct weights dividing the estimated weights by the average weight 
gen weights2 = (weights)/tot
sum weights2


foreach x of varlist culture1 income1 NMIEMB1 educ_basic1-educ_sup1 ///
age051-age661 ccaadummy1-ccaadummy17 yeardummy1-yeardummy9 size_dummy1-size_dummy5  number_spanish1 {

sum `x' [iweight=weights2] if unemp==1
scalar m1`x'=r(mean)
scalar s1`x'=r(sd)
sum `x' [iweight=weights2] if unemp==0
scalar m0`x'=r(mean)
scalar s0`x'=r(sd)
scalar smd`x'=(m1`x'-m0`x')/(sqrt(((s1`x'^2)+(s0`x'^2))/2))
gen smd`x' = smd`x'
sum smd`x'

}
*
* income1 NMIEMB1 educ_basic1-educ_sup1 age051-age661 ccaadummy1-ccaadummy17 yeardummy1-yeardummy9 size_dummy1-size_dummy5  number_spanish
local covs2 income1
gen covs2 = `covs2'

sum covs2 [iweight=weights2] if unemp==1
scalar m1=r(mean)
scalar s1=r(sd)
sum covs2 [iweight=weights2] if unemp==0
scalar m0=r(mean)
scalar s0=r(sd)
scalar smd=(m1-m0)/(sqrt(((s1^2)+(s0^2))/2))
scalar vr=(s1^2)/(s0^2)
dis "standardized mean difference = " smd 
dis "variance ratio = " vr
* restore

